const Koa=require('koa');
const app=new Koa();

//res-time
app.use(async (ctx,next)=>{
    let start=Date.now();
    console.log(1);
    await next();
    console.log(6);
    ctx.set('X-Response-Time',(Date.now()-start)+'ms');
});

//logger
app.use(async (ctx,next)=>{
    let start=Date.now();
    console.log(2);
    await next();
    console.log(`5-Looger: ${ctx.method} ${ctx.url} - ${Date.now()-start}`);
});

app.use(ctx=>{
    console.log(3);
    ctx.body='Hello Koa!';
    console.log(4);
});

app.listen(5000,()=>{
    console.log('Koa2 port:4000----'+new Date().toLocaleTimeString());
});